﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NGI_Logica;
using NGI_Entidades;
using NGI_Auxiliares;

namespace NGI_Sistema.Forms
{
    public partial class NuevoPago : Form
    {
        public NuevoPago()
        {
            InitializeComponent();
        }

        private void NuevoPago_Load(object sender, EventArgs e)
        {
            FuncionesFormulario.CargarCombo(this.cmbCliente, Clientes.CargarTodosConCUIT(), "RazonSocial", "ID");
        }

        private void btnBorrar_Click(object sender, EventArgs e)
        {
            this.txtPagado.Text = "";
            this.txtTotal.Text = "";
            this.cmbCliente.SelectedIndex = -1;
        }

        private void btnAceptar_Click(object sender, EventArgs e)
        {
            if (this.CamposValidos())
            {
                Pago unPago = Pago.Nuevo(Cliente.SinDatos(Convert.ToInt32(cmbCliente.SelectedValue)), Convert.ToDouble(this.txtTotal.Text), Convert.ToDouble(this.txtPagado.Text), Convert.ToDateTime(this.dtpFecha.Text), true);
                Pagos.Crear(unPago, Program.SesionActiva.UsuarioLogueado.ID);

                MessageBox.Show("Pago creado.");
            }
        }


        private Boolean CamposValidos()
        {
            Boolean TodoValido = true;

            if (Convert.ToDouble(this.txtPagado.Text) <= Convert.ToDouble(this.txtTotal.Text))
            {
                TodoValido &= true;
            }
            else
            {
                TodoValido = false;
            }
            this.lblMontoPagadoMayorATotal.Visible = !TodoValido;

            return TodoValido;
        }
    }
}
